<template>
  <div class="app-header">
    <logobox></logobox>
    <top-nav-center></top-nav-center>
    <div class="rightmsg">
      <div class="msgpeople">
        <img :src="headerUrl" alt="" />
        <div class="msgpeople_msg">
          <p>{{ userInfo.name }}</p>
          <p>{{ username }}</p>
        </div>
      </div>
      <!-- <div class=" skinTop-header" >
<a-icon type="skin" theme="filled"/>
    </div> -->

      <i @click="changecolor" class="iconfont skinTop-header dark-header skin">&#xe733;</i>
      <!-- <a-popconfirm title="确认退出系统？" ok-text="是" cancel-text="否" @confirm="outlogin()" placement="bottomRight">
        <i class="iconfont shutdownTop-header skinTop-header">&#xe74f;</i>
      </a-popconfirm> -->
      <span @click="showConfirm">
        <i class="iconfont shutdownTop-header skinTop-header">&#xe74f;</i>
      </span>
    </div>
  </div>
</template>

<script>
import api from '@/api/userConfig';
import logobox from './logobox';
import topNavCenter from './topNavCenter';
import { initUserInfo } from '@/unit/tool';

export default {
  name: 'index',
  components: {
    logobox,
    topNavCenter,
  },
  data() {
    return {
      // headerUrl:require('@images/header-head.png'),
      headerUrl: require('@images/04f.svg'),
      userInfo: {
        name: '',
      },
      username: '',
      flag: 1,
    };
  },
  created() {
    this.username = localStorage.getItem('userName');
    this.getRoleId(this.username);
    let time = null;
    clearInterval(time);
    let i = 0;
    time = setInterval(() => {
      console.log(i++);
      if (window.less || window.less.modifyVars) {
        clearInterval(time);
        if (localStorage.getItem('theme')) {
          let flag = localStorage.getItem('theme');
          this.flag = Number(flag);
          //  setTimeout(()=>{
          this.changeTheme(this.flag);
          //  },1000)
        }
      }
    }, 10);
  },
  methods: {
    showConfirm() {
      let that = this;
      // console.log("打印",this);
      this.$Modal.confirm({
        title: '确认退出系统？',
        onOk() {
          that.outlogin();
        },
        onCancel() {},
      });
    },
    handlemenu(item) {
      console.log('item.path', item.key);
      this.$router.push({ name: item.key });
    },
    changecolor() {
      if (this.flag) {
        this.flag = 0;
      } else {
        this.flag = 1;
      }
      this.changeTheme(this.flag);
    },
    changeTheme(flag) {
      this.$store.commit('board/thisTheme', flag);
      localStorage.setItem('theme', flag);

      let color = null;
      let PageColor = null;
      let fonColor = null;
      let tableHover = null;

      if (flag || flag == 'true') {
        //浅色
        color = '#ffffff';
        PageColor = '#eff3f6';
        fonColor = '#1D2531';
        tableHover = '#b5daf536';
      } else {
        //深色
        color = '#273142';
        PageColor = '#171e29';
        fonColor = '#ffffff';
        tableHover = '#646363';
      }
      window.less.modifyVars({
        '@lightBoxColor': color,
        '@lightPageColor': PageColor,
        '@lightlingtColor': fonColor,
        '@tableHover': tableHover,
      });
    },
    getRoleId(username) {
      // eslint-disable-next-line no-undef
      api.getRoleId({ phoneNumber: username }).then((res) => {
        this.userInfo = res.Data;
        localStorage.setItem('roleId', this.RoleIn(res.Data.compType));
        localStorage.setItem('userId', res.Data.ID);
        if (localStorage.getItem('choseCompanyId')) {
          let compid = localStorage.getItem('compid');
          if (compid != res.Data.compid) {
            localStorage.removeItem('choseCompanyId');
            localStorage.removeItem('choseCompanyname');
          }
        }
        localStorage.setItem('compid', res.Data.compid);
        localStorage.setItem('userName', username);
        let fullpath = this.$route.fullpath;
        if (this.RoleIn(res.Data.compType) == 1 && fullpath == '/distributionMap') {
          localStorage.setItem('navType', 1);
          this.$router.push('/');
        } else if (fullpath == '/') {
          localStorage.setItem('navType', 3);
          this.$router.push('/distributionMap');
        }
      });
    },
    RoleIn(ID) {
      switch (parseInt(ID)) {
        case 1:
          return 3;
        case 2:
          return 2;
        case 3:
          return 1;
        default:
          break;
      }
    },
    outlogin() {
      localStorage.clear();
      this.$router.push('/login');
    },
  },
};
</script>

<style scoped="scoped" lang="less">
@import '~@assets/styles/varibless.less';
@import './style.less';
.top-menu {
  width: 500px;
}
</style>
